from kafka import KafkaProducer
import json
#172.26.10.191:9092,172.26.10.163:9092,172.26.10.77:9092
conf = {
    'bootstrap_servers': ["172.26.10.191:9092","172.26.10.163:9092","172.26.10.77:9092"],
    'topic_name': 'tc_test',
}

print('start producer')
producer = KafkaProducer(bootstrap_servers=conf['bootstrap_servers'])

data='''{
    "id": "1",
    "name": "name1",
    "age": 32
}'''

for i in range(10):
    d=dict()
    d['id']=i
    d['name']='name1'
    d['age']=i*10
    jsons=json.dumps(d)
    data = bytes(jsons, encoding="utf-8")
    producer.send(conf['topic_name'], data)
producer.close()
print('end producer')